package com.eliza.base.views.learn.layouts.basic

import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.unit.dp
import androidx.navigation.NavController

//https://developer.android.com/develop/ui/compose/layouts/adaptive/support-different-screen-sizes?hl=zh-cn
object SupportX {

    @Composable
    fun Show(navController: NavController) {
        Column {
            var count by remember {
                mutableIntStateOf(0)
            }
            Button(onClick = { count = (count + 1) % 4 }) {
                Text(text = "LayoutBasicX $count")
            }
            when (count) {
            }
        }
    }

    @Composable
    private fun MtApp(
//        windowSizeClass: WindowSizeClass = currentWindowAdaptiveInfo().windowSizeClass
    ) {
        // Perform logic on the size class to decide whether to show the top app bar.
//        val showTopAppBar = windowSizeClass.windowHeightSizeClass != WindowHeightSizeClass.COMPACT

        // MyScreen knows nothing about window sizes, and performs logic based on a Boolean flag.

    }


    val Title: @Composable (x: String) -> Unit = {
        Text(text = it)
    }
    val Description: @Composable (description: String, showMore: Boolean, onShowMoreToggled: @Composable (state: Boolean) -> Unit) -> Unit =
        { x, showMore, onShowMoreToggled ->
            Text(text = x)
        }
    val Image: @Composable (x: String) -> Unit = {
        Text(text = it)
    }

    @Composable
    fun CardX(
        imageUrl: String,
        title: String,
        description: String
    ) {
        var showMore by remember { mutableStateOf(false) }

        BoxWithConstraints {
            if (maxWidth < 400.dp) {
                Column {
                    Image(imageUrl)
                    Title(title)
                }
            } else {
                Row {
                    Column {
                        Title(title)
                        Description(description, showMore) { newValue ->
                            showMore = newValue
                        }
                    }
                    Image(imageUrl)
                }
            }
        }
    }
}